clear all
set printcolor gs1, permanently
set more off
global dirout ""
global dirgeolocalized ""
global dircenso ""


use "$dircenso/entorno_urbano/MANZANA_EU_09.dta", clear
append using "$dircenso/entorno_urbano/MANZANA_EU_15.dta"
rename ENT CVE_ENT
rename MUN CVE_MUN
rename LOC CVE_LOC
rename AGEB CVE_AGEB
rename MZA CVE_MZA
save "$dircenso/entorno_urbano/MANZANA_EU_CDMX.dta", replace

use "$dirgeolocalized/collapsed_uber_censo_lessthan500mts.dta", clear
keep year ID trips_card fares_card trips_cash fares_cash dist_to_edomex dist_to_df id ///
CVE_ENT NOM_ENT CVE_MUN NOM_MUN CVE_LOC NOM_LOC CVE_AGEB CVE_MZA POBTOT VIVTOT

use "$dirgeolocalized/collapsed_uber_censo_lessthan500mts.dta", clear
keep year ID trips_card fares_card trips_cash fares_cash ///
CVE_ENT NOM_ENT CVE_MUN NOM_MUN CVE_LOC NOM_LOC CVE_AGEB CVE_MZA POBTOT VIVTOT

egen trips=rowtotal(trips_card trips_cash)
egen fares=rowtotal(fares_card fares_cash)
gen share_cash=fares_cash/fares

tsset ID year
tsfill, full
foreach var in trips fares {
replace `var'=0 if `var'==.
}
by ID: carryforward CVE_ENT CVE_MUN CVE_LOC CVE_AGEB CVE_MZA, replace

capture drop d_trips d_fares
gen d_trips=2*(trips-l.trips)/(trips+l.trips)
gen d_fares=2*(fares-l.fares)/(fares+l.fares)

keep if year==2017

keep CVE_ENT CVE_MUN CVE_LOC CVE_AGEB CVE_MZA trips fares d_* share_cash POBTOT VIVTOT
duplicates drop
merge 1:1 CVE_ENT CVE_MUN CVE_LOC CVE_AGEB CVE_MZA using ///
 "$dircenso/entorno_urbano/MANZANA_EU_CDMX.dta", ///
 keepusing(CONJHAB RECUCALL_ ALUMPUB_ TELPUB_ TRANSCOL_ ACESOAUT_) keep(match) nogenerate
 
keep if CONJHAB==3
keep if CVE_ENT=="15"

capture label drop RECUCALL_l
label define RECUCALL_l 1 "All roads" 2 "Some roads" 3 "No roads"
label values RECUCALL_ RECUCALL_l  


graph bar share_cash if RECUCALL_!=4 [w=POBTOT], over(RECUCALL_)  ///
bar(1, color(blue) lcolor(black))  ///
title(" ") ytitle("Share of cash by availability of pavement") ///
graphregion(color(white)) bgcolor(white) 
graph export "$dirout/FigureC7c.eps", replace


capture label drop ALUMPUB_l
label define ALUMPUB_l 1 "All streets" 2 "Some strees" 3 "No streets"
label values ALUMPUB_ ALUMPUB_l  
graph bar share_cash if ALUMPUB_!=4, over(ALUMPUB_)  ///
bar(1, color(blue) lcolor(black))  ///
title(" ") ytitle("Share of cash by availability of street light") ///
graphregion(color(white)) bgcolor(white) 
graph export "$dirout/FigureC7a.eps", replace



capture label drop TRANSCOL_
label define TRANSCOL_l 1 "All streets" 2 "Some strees" 3 "No streets"
label values TRANSCOL_ TRANSCOL_l  
graph bar share_cash if TRANSCOL_!=4 , over(TRANSCOL_)  ///
bar(1, color(blue) lcolor(black))  ///
title(" ") ytitle("Share of cash by presence of public transport") ///
graphregion(color(white)) bgcolor(white) 
graph export "$dirout/FigureC7b.eps", replace


capture label drop ACESOAUT_
label define ACESOAUT_l 1 "All roads" 2 "Some roads" 3 "No roads"
label values ACESOAUT_ ACESOAUT_l  
graph bar share_cash if ACESOAUT_!=4, over(ACESOAUT_)  ///
bar(1, color(blue) lcolor(black))  ///
title(" ") ytitle("Share of cash by access to cars") ///
graphregion(color(white)) bgcolor(white) 
graph export "$dirout/FigureC7d.eps", replace



